#include "CheckStatusTask.h"
#include "../packages/msg/CliCeckStatusMalformedURL.h"
#include "../../../core/Impp.h"

namespace Impp
{

CheckStatusTask::CheckStatusTask(Oscar* oscar, Buddy* buddy,const qword  & requestId) :
	Task(TASK_CHECK_STATUS, oscar,TASK_HANDLE_REQUESTID,requestId,(time_t)6000), buddy(buddy)
{
}

CheckStatusTask::~CheckStatusTask()
{
}

bool CheckStatusTask::userXOnlineXInfo(const Status & status){
	if(status != OFFLINE){
		wxLogDebug(wxT("CheckStatusTask::userXOnlineXInfo: %s was found!"), buddy->getName().c_str());
		return true;
	}
	wxLogDebug(wxT("CheckStatusTask::userXOnlineXInfo: %s was  not found, sending check package!"), buddy->getName().c_str());

	//0x7, 0x8, 0xC

	msgType = 0x0C;

	OscarServerCon* bos = oscar->getBosConnection();
	qword cookie = (qword) wxDateTime::GetTimeNow();
	dword requestId = bos->nextRequestId();

	handle = requestId;

	bos->sendPackage(DATA, new CliCeckStatusMalformedURL(buddy,cookie,requestId, msgType), PRIORITY_HIGHT,TASK_HANDLE_SEQNR,requestId);

	return false;

}

void CheckStatusTask::msgAck(){
	wxLogDebug(wxT("CheckStatusTask::msgAck: %s is really Offline...!, msgType: %X"), buddy->getName().c_str(), msgType);
	//check next
	/*
	msgType++;

	OscarServerCon* bos = oscar->getBosConnection();
	qword cookie = (qword) wxDateTime::GetTimeNow();
	dword requestId = bos->nextRequestId();

	handle = requestId;

	bos->sendPackage(DATA, new CliCeckStatusMalformedURL(buddy,cookie,requestId, msgType), PRIORITY_HIGHT,TASK_HANDLE_SEQNR,requestId);
	 */
}

void CheckStatusTask::icbmError(){
	wxLogDebug(wxT("CheckStatusTask::icbmError: %s was found...! msgType %x"), buddy->getName().c_str(), msgType);
	Impp::exemplar()->processBuddyStatusChanged(buddy, INVISIBLE|UNKNOWN, wxEmptyString);
}

void CheckStatusTask::timedOut(){
	wxLogDebug(wxT("CheckStatusTask::timedOut: failed!"));
}

}
